
<template>

    <div class="common-layout w-full h-screen">
      <el-container class=" h-full">
        <el-header class=" text-2xl text-center shadow-2xl border-b-4 flex items-center justify-center">小站后台管理</el-header>
        <el-container>
          <el-aside width="200px" class="bg-gray-100 border-r-2 border-gray-300">
            <el-menu>
              <el-menu-item index="1" @click="toUser" class="bg-gray-200 border-b-2 border-b-gray-300 ">
                <template #title>
                  <el-icon></el-icon>
                  <span>已审核</span>
                </template>
              </el-menu-item>
              <el-menu-item index="2" @click="toCards" class="border-b-2 bg-gray-200 border-b-gray-300">
                <template #title>
                  <el-icon></el-icon>
                  <span>审核资源</span>
                </template>
              </el-menu-item>
            </el-menu>
          </el-aside>
          <el-container class="bg-gray-200">

            <el-main v-if="!userPermission" class="flex justify-center items-center">
              <el-card class="w-1/2">
                <template #header>
                  <div class="card-header">
                    <span class="text-2xl">警告</span>
                  </div>
                </template>
                <p class="text-3xl font-bold">您暂无权限进入该后台</p>
                <p class="text-2xl font-bold text-gray-600">{{times}}秒后返回主页</p>
            </el-card>
            </el-main>
            <el-main v-if="userPermission" class="h-96"><el-scrollbar>
              <router-view  :key="$route.fullPath"></router-view>
            </el-scrollbar>
            R</el-main>
            <el-footer class="bg-gray-600"></el-footer>
          </el-container>
        </el-container>
      </el-container>
    </div>
</template>

<script>
import axios from "axios";

export default {
  data(){
    return {
    userPermission:false,
      times:0
    }
  },
  methods: {
    toUser() {
      this.$router.push('/userManage')
    },
   toCards(){
      this.$router.push('/readCard')
   }
  },
  mounted() {
     const token = localStorage.getItem('token')
    if (token) {
      axios.post("http://113.44.66.99:8080/getUserMessage",{},{
        headers:{
          Authorization: token
        }
      }).then((response) => {
        const permission=response.data.data.userPerMission;
        if(permission==0){
          this.userPermission=false
          this.times=5
          const timer=setInterval(()=>{
            this.times-=1;
            if(this.times==0){
              clearInterval(timer);
             window.open("http://113.44.66.99:3000","_self");
            }
          },1000)

        }else if(permission==1){
          this.userPermission=true
        }
      })
    }
  }
}

</script>

<style>
*{
  margin: 0;
  padding: 0;
}




</style>